<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<div th:replace="admin/module/_header"></div>
<div class="wrapper">
    <!-- 菜单栏模块 -->
    <div th:replace="admin/module/_sidebar"></div>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">

        <section class="content-header">
            <h1 style="display: inline-block;">菜品预告详情</h1>
            <ol class="breadcrumb">
                <li>
                    <a data-pjax="true" href="#"><i
                            class="fa fa-dashboard"></i> 首页</a>
                </li>
                <li>
                    <a data-pjax="true" href="#">菜品预告管理</a>
                </li>
                <li class="active">详情</li>
            </ol>
        </section>
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <!-- form start -->

                        <div class="box-body">
                            <div class="row">
                                <form id="form">
                                    <div class="col-md-12">

                                        <input type="hidden" id="id" name="id" th:value="${item.id}">


                                        <div class="row">
                                            <div class="col-md-6">

                                                <div class="form-group">
                                                    <label>所属店铺</label>
                                                    <select class="form-control" id="storeId" name="storeId" disabled>
                                                        <option value="-1">请选择店铺</option>
                                                        <option th:if="${storeList.size() == 1}"
                                                                th:each="store : ${storeList}" th:value="${store.id}"
                                                                selected>[[${store.name}]]
                                                        </option>
                                                        <option th:if="${storeList.size() != 1}"
                                                                th:each="store : ${storeList}" th:value="${store.id}"
                                                                th:selected="${item.storeId == store.id}">
                                                            [[${store.name}]]
                                                        </option>
                                                    </select>
                                                </div>

                                                <div class="form-group">
                                                    <label>预告类型</label>
                                                    <select class="form-control" id="type" name="type" disabled>
                                                        <option value="-1">请选择预告类型</option>
                                                        <option th:each="typeItem : ${typeList}" th:value="${typeItem}"
                                                                th:selected="${item.type == typeItem}">[[${typeItem}]]
                                                        </option>
                                                    </select>
                                                </div>

                                                <div class="form-group">
                                                    <label>菜品名称</label>
                                                    <input type="text" class="form-control" id="name" name="name" disabled
                                                           th:value="${item.name}">
                                                </div>

                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <div class="col-md-4">
                                                        <label>菜品照片</label>
                                                        <div class="input-group">
                                                            <input type="hidden" class="form-control"
                                                                   id="photo"
                                                                   name="photo" th:value="${item.photo}">
                                                            <span class="input-group-btn">
                                                    <input type="file" id="file" accept=".png, .jpg, .jpeg"
                                                           style="display: none">
                                                    </span>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-8">
                                                        <img th:src="${item.photo}" id="photoImg" style="width: 200px;"
                                                             alt="">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>


                                        <div class="form-group">
                                            <label>菜品预告描述</label>
                                            <div th:utext="${item.content}"></div>
                                        </div>


                                    </div>
                                </form>


                            </div>

                            <!-- /.box-body -->
                            <div class="box-footer">
                                <a href="/admin/dishNotice" type="button" class="btn btn-info btn-sm">返回</a>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </section>
        <script>




            /**
             * 提交
             * @param status 状态
             */
            function save() {
                let type = $('#type').val();
                let storeId = $('#storeId').val();
                let name = $('#name').val();
                let photo = $('#photo').val();
                if (storeId == '' || type == '' || name == '' || photo == '') {
                    showErrorMsg('请输入完整信息');
                    return;
                }
                $.ajax({
                    type: 'POST',
                    url: '/admin/dishNotice/save',
                    async: false,
                    data: {
                        'id': $('#id').val(),
                        'name': $('#name').val(),
                        'photo': $('#photo').val(),
                        'storeId': $('#storeId').val(),
                        'type': $('#type').val(),
                        'content': tinymce.activeEditor.getContent()
                    },
                    success: function (data) {
                        if (data.code == 1) {
                            showMsgAndRedirect("保存成功", "success", 1000, "/admin/dishNotice/list");
                        } else {
                            showMsg(data.msg, "error", 1000);
                        }
                    }
                });
            }


            $('body').on('change', '#file', function () {
                var formData = new FormData();
                var files = $($(this))[0].files[0];
                formData.append("file", files);
                $.ajax({
                    url: '/admin/file/upload',
                    type: 'POST',
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: 'json',
                    success: function (res) {
                        console.log(res);
                        $('#photo').val(res.link);
                        $('#photoImg').attr('src', res.link);
                    }
                    , error: function (res) {
                    }
                });
            })


        </script>
    </div>

</div>
<div th:replace="admin/module/_footer"></div>